package com.chinaisafe.user.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.chinaisafe.base.mybatisplus.entity.BaseEntity;
import com.chinaisafe.module.user.request.SysRoleReqVO;
import com.chinaisafe.module.user.response.SysRoleRespVO;
import io.swagger.v3.oas.annotations.media.Schema;
import com.chinaisafe.user.dto.SysRoleDTO ;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.io.Serial;

/**
 * SysRole
 * Description：角色实体类
 *
 * @author tby
 * @date  2024-07-15 17:11:11
 */
@Getter
@Setter
@Accessors(chain = true)
@TableName("sys_role")
@Schema(name = "SysRole", description = "角色")
public class SysRole extends BaseEntity {

    @Serial
    private static final long serialVersionUID = 1L;

    @Schema(description = "名称")
    @TableField("`name`")
    private String name;

    @Schema(description = "角色类型:超级管理员/平台管理员/系统管理员")
    @TableField("`type`")
    private String type;

    @Schema(description = "是否启用")
    @TableField("`enable`")
    private Boolean enable;

    /**
     * 将请求值对象装换为实体类
     *
     * @param reqVO 请求值对象
     * @return SysRole
     * @author tby
     * @date 2024-07-15 17:11:11
     */
    public static SysRole convertFromReqVo(SysRoleReqVO reqVO) {
        SysRole entity = new SysRole();
        entity.setId(reqVO.getId());
        entity.setVersion(reqVO.getVersion());
        // 给实体对应的字段赋值 可根据实际业务删减
        entity.setName(reqVO.getName());
        entity.setType(reqVO.getType());
        entity.setEnable(reqVO.getEnable());
        return entity;
    }

    /**
     * 将实体类转换为响应值对象
     *
     * @return SysRoleRespVO
     * @author tby
     * @date 2024-07-15 17:11:11
     */
    public SysRoleRespVO convertToRespVO() {
        SysRoleRespVO respVo = new SysRoleRespVO();
        respVo.setId(this.getId());
        respVo.setVersion(this.getVersion());
        // 给响应值对象对应的字段赋值 可根据实际业务删减
        respVo.setName(this.getName());
        respVo.setType(this.getType());
        respVo.setEnable(this.getEnable());
        return respVo;
    }

    /**
     * 将实体类转换为传输值对象
     *
     * @return SysRoleDTO
     * @author tby
     * @date 2024-07-15 17:11:11
     */
    public SysRoleDTO convertToDTO() {
        SysRoleDTO dto = new SysRoleDTO();
        dto.setId(this.getId());
        // 给传输值对象对应的字段赋值 可根据实际业务删减
        dto.setName(this.getName());
        dto.setType(this.getType());
        dto.setEnable(this.getEnable());
        return dto;
    }
}
